package uk.ac.lkl.lpp.ui;

import javax.swing.JLabel;
import javax.swing.JComboBox;

//import java.util.PropertyResourceBundle;
import junit.framework.TestCase;

public class MessagesTest extends TestCase {

	public static final String  T_STRING = "all clear";
	public static final String  T_INT_S  = "100";    
	public static final Integer T_INT    = new Integer(T_INT_S);
	public static final Float   T_FLOAT  = new Float(0.123);
	public static final JLabel  T_JLABEL = new JLabel("miko") {
		{setToolTipText("biko");}
	};
	public static final String[] T_JCOMBO_VALS = {"einee","minee","minie","mo"};
	
	public static final String T_STRING_KEY = "testString";
	public static final String T_INT_KEY    = "testInteger";
	public static final String T_FLOAT_KEY  = "testFloat";
	public static final String T_JLABEL_KEY = "testJLabel";
	public static final String T_JCOMBO_KEY = "testJCombo";
		
	public void testGetBundle() {
		if (Messages.getBundle() == null) fail("null bundle");
	}

	public void testGetString() {
		String s = Messages.getBundle().getString(T_STRING_KEY);
		if (s == null) fail("Null testString");
		if (!s.equals(T_STRING)) fail("got "+s);
	}
	
	public void testGetJLabel() {
		JLabel jl = Messages.getJLabel(T_JLABEL_KEY);
		if (jl == null) fail("null JLabel");
		if (!T_JLABEL.getText().equals(jl.getText())) fail("expected label miko. got "+jl.getText());
		if (!T_JLABEL.getToolTipText().equals(jl.getToolTipText())) fail("expected tip biko. got "+jl.getToolTipText());
	}
	

	public void testGetJCombo(){
		JComboBox jcb = Messages.getJCombo(T_JCOMBO_KEY);
		int j = jcb.getItemCount();
		if (j != T_JCOMBO_VALS.length) {
			fail("expeced "+T_JCOMBO_VALS.length +" items, found "+j+" " );
		}
	}
	/*
	public void testGetObject() {
		Integer i = null;
		Object o = null;
		Float f = null;
		
		try {
			o = Messages.getBundle().getObject(T_INT_KEY);
			if (o == null) fail("Null int");
			i = (Integer) o;
		} catch (ClassCastException e) {
			fail(e+": expected Integer, got "+ o+" ("+o.getClass()+")");
		}
		if (!T_INT.equals(i)) fail("got int "+i);
		f = (Float) Messages.getBundle().getObject(T_INT_KEY);
		if (f == null) fail("Null float");
		if (!T_FLOAT.equals(f)) fail("got float "+f);
		
	}
	
	
	public void testHandleGetObject(){
		Object o = ((PropertyResourceBundle)Messages.getBundle()).handleGetObject(T_INT_KEY);
		if (o == null) fail("null o");
		Integer i = null;
		try {
			i = (Integer)o;
		} catch (ClassCastException e) {
			fail ("expected Integer, got "+o.getClass());
		}
		if (!T_INT.equals(i)) fail ("expected "+T_INT+", got "+i);
	}
	*/

}
